package com.example.behavior.controller;

import com.alibaba.fastjson.JSON;
import com.example.behavior.service.ApFollowBehaviorService;
import com.usian.common.kafka.KafkaTopic;
import com.usian.model.behavior.pojos.ApFollowBehavior;
import com.usian.model.common.dtos.ResponseResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestBody;

import java.util.Date;

@Component
@Slf4j
public class KafukaListen {
    @Autowired
    private ApFollowBehaviorService apFollowBehaviorService;
    @KafkaListener(topics = KafkaTopic.TOPIC)
    public void getMessage(String  message){
        System.out.println(message);
        ApFollowBehavior apFollowBehavior = JSON.parseObject(message, ApFollowBehavior.class);
        apFollowBehavior.setCreatedTime(new Date());
        ResponseResult insert = apFollowBehaviorService.insert(apFollowBehavior);
        log.info("==========>{}",insert);
    }
}
